<?php
function detection_mobile ()
{
	if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))
		return true;

	if (isset ($_SERVER['HTTP_ACCEPT']))
	{
		$accept = strtolower($_SERVER['HTTP_ACCEPT']);
		if (strpos($accept, 'wap') !== false)
			return true;
	}

	if (isset ($_SERVER['HTTP_USER_AGENT']))
	{
		if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false)
			return true;

		if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false)
			return true;
	}

	return false;
}

function dateToMysql($date)
{
	if(empty($date))
		return date( 'Y-m-d H:i:s', 0);
	preg_match("#([0-9]{2})/([0-9]{2})/([0-9]{4}) ([0-9]{2}):([0-9]{2})#",$date,$dateData);
	return date( 'Y-m-d H:i:s', strtotime($dateData[3]."-".$dateData[2]."-".$dateData[1]." ".$dateData[4].":".$dateData[5]));
}

function dateToMysqlHless($date)
{
	if(empty($date))
		return date( 'Y-m-d H:i:s', 0);
	preg_match("#([0-9]{2})/([0-9]{2})/([0-9]{4})#",$date,$dateData);
	return date( 'Y-m-d', strtotime($dateData[3]."-".$dateData[2]."-".$dateData[1]));
}

function dateFromMysql($date,$form=false)
{
	if(empty($date))
		return "";
	preg_match("#([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})#",$date,$array);
	if($array[1]=="1970")
		return "";
	if(!$form&&$array[4]=="00"&&$array[4]=="00")
		return $array[3]."/".$array[2]."/".$array[1];
	return $array[3]."/".$array[2]."/".$array[1]." ".$array[4].":".$array[5];
}

function dateFromMysqlHless($date)
{
	if(empty($date))
		return "";
	preg_match("#([0-9]{4})-([0-9]{2})-([0-9]{2})#",$date,$array);
	if($array[1]=="1970")
		return "";
	return $array[3]."/".$array[2]."/".$array[1];
}
?>